<template>
  <div class="book-card" @click="$emit('click')">
    <div class="book-cover">
      <img :src="book.cover" :alt="book.title" />
    </div>
    
    <div class="book-info">
      <h3 class="book-title">{{ book.title }}</h3>
      <p class="book-author">{{ book.author }}</p>
      
      <div class="book-rating">
        <el-rate
          v-model="book.rating"
          disabled
          show-score
          text-color="#ff6b6b"
          score-template="{value}"
        />
      </div>
      
      <div class="book-price">
        <span class="price">¥{{ book.price.toFixed(2) }}</span>
      </div>
      
      <el-button type="primary" class="add-to-cart" @click.stop="addToCart">
        加入购物车
      </el-button>
    </div>
  </div>
</template>

<script setup>
import { ElMessage } from 'element-plus'

defineProps({
  book: {
    type: Object,
    required: true
  }
})

const addToCart = () => {
  // 模拟添加到购物车
  ElMessage.success('已添加到购物车')
}
</script>

<style scoped>
.book-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  overflow: hidden;
  transition: transform 0.3s, box-shadow 0.3s;
  cursor: pointer;
}

.book-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.book-cover {
  width: 100%;
  height: 250px;
  overflow: hidden;
}

.book-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-info {
  padding: 16px;
}

.book-title {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 8px;
  color: #333;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-author {
  font-size: 14px;
  color: #666;
  margin-bottom: 8px;
}

.book-rating {
  margin-bottom: 8px;
}

.book-price {
  margin-bottom: 12px;
}

.price {
  font-size: 18px;
  font-weight: bold;
  color: #ff6b6b;
}

.add-to-cart {
  width: 100%;
}
</style>
